package functionalTest;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import util.DateUtil;
import domain.Driver;
import domain.Person;
import domain.Route;
import domain.Schedule;
import domain.ScheduleStatus;


public class DriverUnitTest {
	Driver driver = null;
	Person person = null;
	
	@Before
	public void setUp() throws Exception {
		person = new Person();
		person.setFullName("Anucha");
		person.setUserName("driver1");
		person.setPassword("driver1");
		
		driver = new Driver();
		person.addRoles(driver);
		
		Schedule tschedule = new Schedule();
		tschedule.setRoute(Route.R12);
		tschedule.setDate(DateUtil.getCurrentTimestamp());
		tschedule.setStatus(ScheduleStatus.priortized);
		
		driver.addSchedules(tschedule);
	}

	@After
	public void tearDown() throws Exception {
		driver = null;
		person = null;
	}

	@Test
	public void testGetNotPassedSchedules1() {
		
		assertEquals(driver.getNotPassedSchedules().size(), 1);
	}
	
	@Test
	public void testGetNotPassedSchedules2() {
		
		Schedule tschedule = new Schedule();
		tschedule.setRoute(Route.R12);
		tschedule.setDate(DateUtil.getCurrentTimestamp());
		tschedule.setStatus(ScheduleStatus.priortized);
		
		driver.addSchedules(tschedule);
		
		assertEquals(driver.getNotPassedSchedules().size(), 2);
	}
	
	@Test
	public void testGetNotPassedSchedules3() {
		
		Schedule tschedule = new Schedule();
		tschedule.setRoute(Route.R12);
		tschedule.setDate(DateUtil.getTimestampFromDDMMYYYY("11/08/2000", 0));
		tschedule.setStatus(ScheduleStatus.priortized);
		
		driver.addSchedules(tschedule);
		
		assertEquals(driver.getNotPassedSchedules().size(), 1);
	}
	
	@Test
	public void testGetPassedSchedules1() {
		assertEquals(driver.getPassedSchedules().size(), 0);
	}
	
	@Test
	public void testGetPassedSchedules2() {
		
		Schedule tschedule = new Schedule();
		tschedule.setRoute(Route.R12);
		tschedule.setDate(DateUtil.getTimestampFromDDMMYYYY("11/08/2000", 0));
		tschedule.setStatus(ScheduleStatus.completed);
		
		driver.addSchedules(tschedule);
		
		driver.addSchedules(tschedule);
		
		assertEquals(driver.getNotPassedSchedules().size(), 1);
	}
	
	@Test
	public void testGetPassedSchedules3() {
		
		Schedule tschedule = new Schedule();
		tschedule.setRoute(Route.R12);
		tschedule.setDate(DateUtil.getTimestampFromDDMMYYYY("11/08/2000", 0));
		tschedule.setStatus(ScheduleStatus.completed);
		
		Schedule tschedule2 = new Schedule();
		tschedule2.setRoute(Route.R12);
		tschedule2.setDate(DateUtil.getTimestampFromDDMMYYYY("11/08/2000", 0));
		tschedule2.setStatus(ScheduleStatus.completed);
		
		Schedule tschedule3 = new Schedule();
		tschedule3.setRoute(Route.R12);
		tschedule3.setDate(DateUtil.getCurrentTimestamp());
		tschedule3.setStatus(ScheduleStatus.priortized);
		
		driver.addSchedules(tschedule);
		driver.addSchedules(tschedule2);
		driver.addSchedules(tschedule3);
		
		assertEquals(driver.getNotPassedSchedules().size(), 2);
	}
}
